from config import BaseConfig
from peewee import *

config = BaseConfig()
db = PostgresqlDatabase(f"postgresql://{config.postgres_user}:{config.postgres_password}@localhost:15432/{config.postgres_db}")
# db = SqliteDatabase("database.db")

class User(Model):
    username = CharField(unique=True)
    password = CharField()
    role = CharField(choices=['admin', 'cook', 'waiter'])
    fired = BooleanField(default=False)

    class Meta:
        database = db
        
class Shift(Model):
    date = DateField()
    start_time = TimeField()
    end_time = TimeField()
    waiters = ManyToManyField(User, backref='shifts')
    cooks = ManyToManyField(User, backref='shifts')
    
    class Meta:
        database = db

class Order(Model):
    table_number = IntegerField()
    num_guests = IntegerField()
    items = TextField()
    status = CharField(choices=['placed', 'paid', 'preparing', 'ready'])
    waiter = ForeignKeyField(User, backref='orders')
    
    class Meta:
        database = db